package com.bw.zg3park2212.signlist

import androidx.appcompat.widget.SearchView
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.entity.SiginEntity
import com.bw.base.entity.SiginEntityItem
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.adpter.SiginListAdpter
import com.bw.zg3park2212.databinding.ActivitySiginlistBinding

import dagger.hilt.android.AndroidEntryPoint
import java.util.Calendar

@AndroidEntryPoint
@Route(path = "/app/SiginlistActivity")
    class SiginlistActivity : BaseActivity<ActivitySiginlistBinding,SiginViewModel>() {
    lateinit var siginListAdpter: SiginListAdpter
    var month=5
    lateinit var sgin:List<SiginEntityItem>
    override fun intitView() {
        siginListAdpter= SiginListAdpter()
        binding.rv.adapter=siginListAdpter
        binding.rv.layoutManager=LinearLayoutManager(this)
        viewmodel.getsiginlist(781)
        binding.tvMonth.text=month.toString()
        siginListAdpter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build("/app/SignActivity").navigation()
        }
    }

    override fun intitData() {
        viewmodel.siginlistSuccse.observe(this){
            siginListAdpter.data.clear()
            siginListAdpter.data.addAll(it)
            it.forEach {
                if (it.morningCheckIn.isNullOrEmpty()){
                    it.type=1
                }else{
                    it.type=0
                }
            }
            sgin=it
            binding.rgAll.setOnClickListener {
                siginListAdpter.data.clear()
                siginListAdpter.addData(sgin)
                siginListAdpter.notifyDataSetChanged()
            }
            binding.rgZhengchang.setOnClickListener {it1->
                siginListAdpter.data.clear()
                siginListAdpter.addData(sgin.filter {
                    it.status=="正常"
                })
                siginListAdpter.notifyDataSetChanged()
            }
            binding.rgYijujue.setOnClickListener {
                siginListAdpter.data.clear()
                siginListAdpter.addData(sgin.filter {
                    it.status=="早退"
                })
                siginListAdpter.notifyDataSetChanged()
            }
            binding.rgChidao.setOnClickListener {
                siginListAdpter.data.clear()
                siginListAdpter.addData(sgin.filter {
                    it.status=="迟到"
                })
                siginListAdpter.notifyDataSetChanged()
            }
            //搜索月份
//            binding.sv.setOnQueryTextListener(object :SearchView.OnQueryTextListener{
//                override fun onQueryTextSubmit(query: String?): Boolean {
//
//                    return false
//                }
//
//                override fun onQueryTextChange(newText: String?): Boolean {
//                    siginListAdpter.data.clear()
//                    if (newText!=null){
//                       siginListAdpter.addData(sgin.filter {
//                           if (it.morningCheckIn.isNullOrEmpty()){
//                               it.afternoonCheckIn.split("/")[1].contains(newText)
//                           }else{
//                               it.morningCheckIn.split("/")[1].contains(newText)
//                           }
//                       })
//                    }
//                    siginListAdpter.notifyDataSetChanged()
//                    return false
//                }
//            })
            //点击左右控制月份
            binding.left.setOnClickListener {
                month--
                binding.tvMonth.text= month.toString()
                siginListAdpter.data.clear()
                siginListAdpter.addData(sgin.filter {
                    if (it.morningCheckIn.isNullOrEmpty()){
                        it.afternoonCheckIn.split("/")[1].contains(month.toString())
                    }else
                        it.morningCheckIn.split("/")[1].contains(month.toString())
                })
                siginListAdpter.notifyDataSetChanged()
            }
            binding.right.setOnClickListener {
                month++
                binding.tvMonth.text= month.toString()
                siginListAdpter.data.clear()
                siginListAdpter.addData(sgin.filter {
                    if (it.morningCheckIn.isNullOrEmpty()){
                        it.afternoonCheckIn.split("/")[1].contains(month.toString())
                    }else
                        it.morningCheckIn.split("/")[1].contains(month.toString())
                })
                siginListAdpter.notifyDataSetChanged()
            }
//            siginListAdpter.addData(sgin.filter {
//                if (it.morningCheckIn.isNullOrEmpty()){
//                    it.afternoonCheckIn.split("/")[1].contains(month.toString())
//                }else {
//                    it.morningCheckIn.split("/")[1].contains(month.toString())
//                }
//            })
            siginListAdpter.notifyDataSetChanged()
        }
    }

}